<?php
namespace app\common\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;

class ViewsLinkCommand extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('views:link');
        // 设置参数
        $this->setDescription('Create a symbolic link from "public/views" to "views"');
    }

    protected function execute(Input $input, Output $output)
    {
    	// 指令输出
        $this->link(views_path(), public_path('views'));
        // 指令输出
        $output->writeln('The [public/views] directory has been linked.');
    }
    
    
    public function link($target, $link)
    {
        if (! windows_os()) {
            return symlink($target, $link);
        }
    
        $mode = $this->isDirectory($target) ? 'J' : 'H';
        exec("mklink /{$mode} ".escapeshellarg($link).' '.escapeshellarg($target));
    }
    
    public function isDirectory($directory)
    {
        return is_dir($directory);
    }

}



